package hlhj.fhp.checkpoint.atys

import android.content.Intent
import android.view.View
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.iview.HomeSelfView
import hlhj.fhp.checkpoint.iview.WalletView
import hlhj.fhp.checkpoint.javaBean.MyBaseBean
import hlhj.fhp.checkpoint.javaBean.UserInfoBean
import hlhj.fhp.checkpoint.presenter.HomePresenter
import hlhj.fhp.checkpoint.presenter.HomeSelfPresenter
import hlhj.fhp.checkpoint.presenter.WalletPresenter
import kotlinx.android.synthetic.main.aty_wallet.*
import kotlinx.android.synthetic.main.lo_pub_head.*

/**
 * Created by Never Fear   on 2018\11\12 0012.
Never More....
 */
class WalletAty :BaseAty<WalletView,WalletPresenter>(), WalletView, HomeSelfView {
    private var userPresenter:HomeSelfPresenter?=null
    override fun initView() {
        tvTittle.setText("钱包")
        btRightText.setText("零钱明细")
        btRightText.visibility=View.VISIBLE
    }

    override fun logicStart() {
        userPresenter?.getUserInfo(this)

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode!=-1)return
        when(requestCode){
            1->{
                userPresenter?.getUserInfo(this)
                setResult(-1)
            }
        }
    }
    override fun setListener() {
        btGetCash.setOnClickListener {
            val intent = Intent(this, GetCashAty::class.java)
            intent.putExtra("all",moneyNum.text.toString())
            startActivityForResult(intent,1)
        }
        btRightText.setOnClickListener {
            val intent = Intent(this, MoneyAty::class.java)
            startActivity(intent)
        }
    }

    override fun bindView(): WalletView {
        return this
    }

    override fun setLoginOut(myBaseBean: MyBaseBean) {
    }

    override fun createPresenter(): WalletPresenter {
        userPresenter= HomeSelfPresenter()
        userPresenter?.let {
            it.createModule()
            it.bindView(this)
        }
        return WalletPresenter()
    }

    override fun setUserInfo(userInfoBean: UserInfoBean) {
        moneyNum.text=userInfoBean.info.balance
    }

    override val contentId: Int= R.layout.aty_wallet
}